package actions;

import java.sql.SQLException;
import java.util.Vector;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.sql.RowSet;

import model.AdminModel;

import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

import db.DbException;
import forms.ReviewerFormInsert;
//import model.UniversityModel;
//import model.UserModel;

public class AdminAddReviewerAction extends Action {

	private static final boolean DEBUG = true;
	//private static final int UNKNOWN = -1;
	
	public ActionForward execute(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response) throws DbException {
		
		// get reviewer user info from form
		ReviewerFormInsert rform = (ReviewerFormInsert)form;
		String username = rform.getUsername();
		String password = rform.getPassword();
		
		if (DEBUG) {
			System.err.println("AddReviewerAction: username(" + username +")");
			System.err.println("AddReviewerAction: password(" + password +")");
		}

		// Insert the reviewer
		AdminModel.insertReviewer(rform);

		// Retrieve all reviewers
		RowSet reviewerSet = AdminModel.getAllReviewers();
		
		// Store the RowSet in the request scope
		request.setAttribute("reviewerSet", reviewerSet);
		
		return mapping.findForward("success");
	}
	
}